package com.zzyl.serve.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.common.utils.DateUtils;
import com.zzyl.serve.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Predicate;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.stereotype.Service;
import com.zzyl.serve.mapper.NursingProjectMapper;
import com.zzyl.serve.domain.NursingProject;
import com.zzyl.serve.service.INursingProjectService;

/**
 * 护理项目Service业务层处理
 *
 * @author itheima
 * @date 2025-02-28
 */
@Service
public class NursingProjectServiceImpl extends ServiceImpl<NursingProjectMapper, NursingProject> implements INursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 查询护理项目
     *
     * @param id 护理项目主键
     * @return 护理项目
     */
    @Override
    public NursingProject selectNursingProjectById(Integer id) {
        return nursingProjectMapper.selectNursingProjectById(id);
//        return getById(id);
    }

    /**
     * 查询护理项目列表
     *
     * @param nursingProject 护理项目
     * @return 护理项目
     */
    @Override
    public List<NursingProject> selectNursingProjectList(NursingProject nursingProject) {
//        return nursingProjectMapper.selectNursingProjectList(nursingProject);
        return list(
                new LambdaQueryWrapper<NursingProject>()
                        .like(nursingProject.getName() != null, NursingProject::getName, nursingProject.getName())
                        .eq(nursingProject.getStatus() != null, NursingProject::getStatus, nursingProject.getStatus())
        );
    }

    /**
     * 新增护理项目
     *
     * @param nursingProject 护理项目
     * @return 结果
     */
    @Override
    public int insertNursingProject(NursingProject nursingProject) {
        nursingProject.setCreateTime(DateUtils.getNowDate());
//        return nursingProjectMapper.insertNursingProject(nursingProject);
        return save(nursingProject) ? 1 : 0;
    }

    /**
     * 修改护理项目
     *
     * @param nursingProject 护理项目
     * @return 结果
     */
    @Override
    public int updateNursingProject(NursingProject nursingProject) {
//        nursingProject.setUpdateTime(DateUtils.getNowDate());
//        return nursingProjectMapper.updateNursingProject(nursingProject);
        return updateById(nursingProject) ? 1 : 0;
    }

    /**
     * 批量删除护理项目
     *
     * @param ids 需要删除的护理项目主键
     * @return 结果
     */
    @Override
    public int deleteNursingProjectByIds(Integer[] ids) {
//        return nursingProjectMapper.deleteNursingProjectByIds(ids);
        return removeByIds(Arrays.asList(ids)) ? 1 : 0;
    }

    /**
     * 删除护理项目信息
     *
     * @param id 护理项目主键
     * @return 结果
     */
    @Override
    public int deleteNursingProjectById(Integer id) {
//        return nursingProjectMapper.deleteNursingProjectById(id);
        return removeById(id) ? 1 : 0;
    }


    /**
     * 查询所有 护理项目
     * @return
     */
    @Override
    public List<NursingProjectVo> selectAll() {

        return nursingProjectMapper.selectAll();

    }

    /**
     * 分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */


    @Override
    public List<NursingProject> selectPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<NursingProject> eq = new LambdaQueryWrapper<NursingProject>();
        if (name != null) {
            eq.like(NursingProject::getName, name);
        }
        if (status != null) {
            eq.eq(NursingProject::getStatus, status);
        }
        List<NursingProject> nursingProjec = nursingProjectMapper.selectList(eq);
        return nursingProjec;
    }


}

